package com.macro.mall.service.impl;


import com.macro.mall.dao.MemberMapper;

import com.macro.mall.dao.PmsProductDao;
import com.macro.mall.dto.PmsProductResult;
import com.macro.mall.mapper.PmsCommentMapper;
import com.macro.mall.mapper.PmsProductMapper;
import com.macro.mall.mapper.SmsCouponProductRelationMapper;
import com.macro.mall.model.PmsProduct;
import com.macro.mall.model.SmsCoupon;
import com.macro.mall.model.SmsCouponProductRelation;
import com.macro.mall.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class MemberServiceImpl implements MemberService {
    @Autowired
    private PmsProductMapper productMapper;
    @Autowired
    private PmsCommentMapper couponMapper;
    @Autowired
    private SmsCouponProductRelationMapper smsCouponProductRelationMapper;
    /**
     * 优惠券列表
     */
    @Override
    public List<SmsCoupon> listByProduct(Long id) {
        List<SmsCoupon> list = new ArrayList<>();
        //查询优惠券列表
        //TODO 写死的 只查询全场通用的优惠券
        List<SmsCoupon> Prolist = smsCouponProductRelationMapper.couponList();
        list.addAll(Prolist);
        //查询商品信息
        PmsProduct proId =  productMapper.getProduct(id);

        //查询是否有指定分类的优惠券
        List<Long> couId = smsCouponProductRelationMapper.listByProduct(proId.getProductCategoryId());
        if (null!=couId && couId.size()>0){
            List<SmsCoupon> couIds =  smsCouponProductRelationMapper.selByIds(couId);
            list.addAll(couIds);
        }
        //查询优惠券商品列表
        List<Long> CouproId = smsCouponProductRelationMapper.listCoupon(id);
        if (null!=CouproId && CouproId.size()>0){
            List<SmsCoupon> couponId =  smsCouponProductRelationMapper.CouponId(CouproId);
            list.addAll(couponId);
        }


        return list;
    }
}
